package com.westar;

import com.alibaba.druid.support.http.StatViewServlet;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.MultipartConfigElement;

/**
 * 文件上传的大小过滤器
 */
@Configuration
public class UploadFileConfiguration {
    @Bean
    public MultipartConfigElement multipartConfigElement(){
        MultipartConfigFactory factory = new MultipartConfigFactory();
        factory.setMaxFileSize("500MB");
        factory.setMaxRequestSize("2048MB");
        return factory.createMultipartConfig();
    }

    @Bean
    public ServletRegistrationBean<StatViewServlet> druidStatViewServlet() {
        ServletRegistrationBean<StatViewServlet> registrationBean = new ServletRegistrationBean<>( new StatViewServlet(), "/druid/*" );
        registrationBean.addInitParameter( "allow", "127.0.0.1" );// IP白名单 (没有配置或者为空，则允许所有访问)
        registrationBean.addInitParameter( "deny", "" );// IP黑名单 (存在共同时，deny优先于allow)
        registrationBean.addInitParameter( "loginUsername", "admin" );
        registrationBean.addInitParameter( "loginPassword", "westar" );
        registrationBean.addInitParameter( "resetEnable", "false" );
        return registrationBean;
    }

}